# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=fribidi
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.0.9
pkgrel=1
pkgdesc="A Free Implementation of the Unicode Bidirectional Algorithm (mingw-w64)"
arch=('any')
license=('LGPL')
url="https://github.com/fribidi/fribidi/"
depends=()
options=('strip' '!libtool' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/fribidi/fribidi/archive/v${pkgver}.tar.gz")
sha256sums=('ef6f940d04213a0fb91a0177b2b57df2031bf3a7e2cd0ee2c6877a160fc206df')

build() {
  mkdir -p build-${MINGW_CHOST}-static
  cd build-${MINGW_CHOST}-static

  meson \
      --buildtype plain \
      --prefix=${MINGW_PREFIX} \
       -Ddocs=false \
       --default-library static \
      ../${_realname}-${pkgver}

  ninja

  cd ..
  mkdir -p build-${MINGW_CHOST}-shared
  cd build-${MINGW_CHOST}-shared

  meson \
      --buildtype plain \
      --prefix=${MINGW_PREFIX} \
       -Ddocs=false \
       --default-library shared \
      ../${_realname}-${pkgver}

  ninja
}

check() {
  cd build-${MINGW_CHOST}-shared

  meson test
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}-static
  DESTDIR=${pkgdir}${MINGW_PREFIX} ninja install

  cd ${srcdir}/build-${MINGW_CHOST}-shared
  DESTDIR=${pkgdir}${MINGW_PREFIX} ninja install

  sed -s "s|$(cygpath -m ${MINGW_PREFIX})|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/${_realname}.pc"

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
